import { createRouter, createWebHashHistory } from 'vue-router';
import NProgress from 'nprogress'; // progress bar
import 'nprogress/nprogress.css';

import { appRoutes } from './routes';
import createRouteGuard from './guard';

NProgress.configure({ showSpinner: false }); // NProgress Configuration

const router = createRouter({
  history: createWebHashHistory(),

  routes: [
    {
      path: '/',
      redirect: 'home',
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login/index.vue'),
      meta: {
        requiresAuth: false,
      },
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('@/views/register.vue'),
      meta: {
        requiresAuth: false,
      },
    },
    {
      path: '/recycleBin',
      name: 'recycleBin',
      component: () => import('@/views/recycleBin.vue'),
      meta: {
        requiresAuth: true,
      },
    },
    {
      path: '/preview',
      name: 'preview',
      component: () => import('@/views/preview.vue'),
      meta: {
        requiresAuth: true,
      },
    },
    {
      path: '/team',
      name: 'team',
      component: () => import('@/views/team.vue'),
      meta: {
        requiresAuth: true,
      },
    },
    {
      path: '/project',
      name: 'project',
      component: () => import('@/views/project.vue'),
      meta: {
        requiresAuth: true,
      },
    },
    {
      path: '/home',
      name: 'home',
      component: () => import('@/views/home.vue'),
      meta: {
        requiresAuth: true,
      },
    },
    ...appRoutes,
    {
      path: '/:pathMatch(.*)*',
      name: 'notFound',
      component: () => import('@/views/not-found/index.vue'),
    },
    {
      path: '/info',
      name: 'Info',
      component: () => import('@/views/user/info/index.vue'),
      meta: {
        locale: 'menu.user.info',
        requiresAuth: true,
        roles: ['*'],
      },
    },
  ],
  scrollBehavior() {
    return { top: 0 };
  },
});

createRouteGuard(router);

export default router;
